package com.xique.door.api.factory;

import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.api.RemoteBuildingService;
import com.xique.door.api.request.build.RemoteAreaListRequest;
import com.xique.door.api.request.build.RemoteBuildingListRequest;
import com.xique.door.api.request.build.RemoteHouseListRequest;
import com.xique.door.api.request.build.RemoteHouseUserListRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author shd
 * @create 2022/3/8 11:04
 */
@Component
public class RemoteBuildingFallbackFactory implements FallbackFactory<RemoteBuildingService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteBuildingFallbackFactory.class);

    @Override
    public RemoteBuildingService create(Throwable throwable) {

        log.error("门禁服务调用失败:{}", throwable.getMessage());

        return new RemoteBuildingService() {

            @Override
            public AjaxResult getAreaList(RemoteAreaListRequest request) {
                return AjaxResult.error("获取区域列表信息失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult getBuildingList(RemoteBuildingListRequest request) {
                return AjaxResult.error("获取楼栋列表信息失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult getHouseList(RemoteHouseListRequest request) {
                return AjaxResult.error("获取房屋列表信息失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult getHouseUserList(RemoteHouseUserListRequest request) {
                return AjaxResult.error("获取房屋住户列表信息失败:" + throwable.getMessage());
            }
        };
    }
}
